/*-
  use bamp::ApiParser;
  use bamp::CppApiGen;
  use bamp::CApiGen;

  my $api = bamp::ApiParser->new("../include/bamp/bamp.api", CLASSNAME);
  my $cpp = bamp::CppApiGen->new($api);
  my $c   = bamp::CApiGen->new($api);
  die "API parsing failed" if ${$api}{errors};

  my $class      = CLASSNAME; $class =~ s/::/_/g;
  my $incl_guard = "__".uc($class)."_WRAP_HPP__";
  my $struct     = lc($class);

  my $shortname  = $struct;
  $shortname =~ s/\w+?_//;

  my $interface = $shortname;
  $interface =~ s/^(.)/uc($1)/e;
  $interface =~ s/_(.)/uc($1)/e;
  my $cppclass = $interface."Ptr";

  my @includes = (
  "bamp/".$shortname."_api.hpp",
  "bamp/".$shortname."_ptr.hpp"
  );
*/
/*
 * /*= $cpp->header() */
 */

#include <bamp/rc.h>
#include <bamp/exception.hpp>

/*- for ($api->includes("C++", @includes)) { */
#include </*$_*/>
/*- } */

const char* bamp::/*$cppclass*/::cname = "/*$struct*/";

bamp_rc __/*$struct*/___dctor(void* ctx)
{
    bamp::/*$interface*/* /*$shortname*/ = (bamp::/*$interface*/*)ctx;
    delete /*$shortname*/;
    return BAMP_RC_OK;
}

bamp_rc __/*$struct*/___clone(void** dst, void* src)
{
    bamp::/*$interface*/* /*$shortname*/ = (bamp::/*$interface*/*)src;
    BAMP_RC_CATCH(*dst = /*$shortname*/->clone());
    return BAMP_RC_OK;
}

/*-
  for my $m ($api->all_methods()) {
    my $ret     = $api->first_out($m);
    my $const   = ${$m}{const} ? "const " : "";
    my $cppname = $cpp->meth_name($m);
    my @outlist = ($api->all_out($m));
    my @arglist = $cpp->call_cpp_args($m, "ret_");
    my $call = $shortname."->".$cppname."(".join(", ", @arglist).")";
*/
/*+$c->declare($m, "__".$struct."_", "ctx", "void")*/
{
    /*$const*/bamp::/*$interface*/* /*$shortname*/ = (bamp::/*$interface*/*)ctx;
    /*-
      for my $out (@outlist) {
      next if defined $ret && $out == $ret;
     */
    /*$cpp->arg_type($out)*/ ret_/*${$out}[0]*/;
    /*- } */
    /*- if (defined $ret) { */
    BAMP_RC_CATCH(*/*${$ret}[0]*/ = /*$cpp->arg_to_c($ret, $call)*/);
    /*- } else { */
    BAMP_RC_CATCH(/*$call*/);
    /*- } */
    /*-
      for my $out (@outlist) {
      next if defined $ret && $out == $ret;
    */
    */*${$out}[0]*/ = /*+$cpp->arg_to_c($out, "ret_".${$out}[0])*/;
    /*- } */
    return BAMP_RC_OK;
}

/*- } */
